﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;

namespace DAO_Layer
{
    class MysqlDaoRoles :DAO_Roles
    {
        private String TableName = "roles";
        Sqlconnector mysqlconn;

        public MysqlDaoRoles()
        {
            mysqlconn = new Sqlconnector();

        }
        public List<Rol> queryAll()
        {
            List<Rol> roles = new List<Rol>();

            mysqlconn.Open();

            MySqlCommand comm = new MySqlCommand();
            comm.Connection = mysqlconn.Mysqlconnection;
            comm.CommandText = "SELECT id,nombre,descripcion FROM " + TableName;
            MySqlDataReader myReader = null;

            try
            {
                myReader = comm.ExecuteReader();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            while (myReader.Read())
            {

                Rol r = new Rol();
                r.Id = Int32.Parse(myReader["id"].ToString());
                r.Nombre = myReader["nombre"].ToString();
                r.Descripcion = myReader["descripcion"].ToString();

                roles.Add(r);
            }

            myReader.Close();


            mysqlconn.Close();



            return roles;
        }
    }
}
